<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>天狗商场--商品列表</title>


    <!-- 引入 Vue 和 Vant 的 JS 文件 -->
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6/dist/vue.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vant@2.12/lib/vant.min.js"></script>
    <!-- 引入样式文件 -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vant@2.12/lib/index.css" />

    <style>
        #main {
            margin: 20px 10px 60px 10px;
        }

        .my-swipe .van-swipe-item {
            color: #fff;
            font-size: 20px;
            line-height: 150px;
            text-align: center;
            background-color: #39a9ed;
        }
    </style>
</head>

<body>
<div id="app">

    <!-- 顶部导航 -->
    <van-nav-bar title="天狗商城" left-text="返回" left-arrow>
        <template #right>
            <van-icon name="search" size="18"></van-icon>
        </template>
    </van-nav-bar>

    <van-search
            v-model="value"
            shape="round"
            background="#4fc08d"
            placeholder="请输入搜索关键词"
    ></van-search
    >
    <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
        <van-list v-model:loading="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">

            <van-cell v-for="item in list" :key="item" :title="item">
                <p>内容jewfgskfhgregfaeuef</p>

            </van-cell>

        </van-list>
    </van-pull-refresh>

    <!-- 底部标签页 -->

        <van-tabbar v-model="active" inactive-color="#1989fa" active-color="#ee0a24" @change="onChange">
            <van-tabbar-item icon="home-o">主页</van-tabbar-item>
            <van-tabbar-item icon="smile-o" dot>树洞</van-tabbar-item>
            <van-tabbar-item icon="more-o" badge="5">消息</van-tabbar-item>
            <van-tabbar-item icon="friends-o">我的</van-tabbar-item>
        </van-tabbar>


</div>


<script>
    function goToPage(index) {
        let page = "index.html";
        switch (index) {
            case 0:
                page = "index.html";
                break;
            case 1:
                page = "shudong.html";
                break;
            case 2:
                page = "news.html";
                break;
            case 3:
                page = "my.html";
                break;
        }
        location.href = page;
    }
    let vm = new Vue({
        el: '#app',
        data: {
            active: 2,
            value: '',
            list: ['名称','名称1'],
            loading: false,
            finished: false,
            refreshing: false,
        },
        methods: {
            onChange(index) {
                goToPage(index);
            },

            onLoad() {
                let that = this ;
                // 异步更新数据
                // setTimeout 仅做示例，真实场景中一般为 ajax 请求
                setTimeout(() => {
                    for (let i = 0; i < 10; i++) {
                        that.list.push(that.list.length + 1);
                    }

                    // 加载状态结束
                    that.loading = false;

                    // 数据全部加载完成
                    if (that.list.length >= 40) {
                        that.finished = true;
                    }
                }, 1000);
            },
            onRefresh() {
                let that = this ;
                // 清空列表数据
                //that.finished = true;

                // 重新加载数据
                // 将 loading 设置为 true，表示处于加载状态
                that.loading = false;
                that.onLoad();
                //console.log("refresh");
            },


        },
        mounted() {

        }
    });
</script>
</body>

</html>
